/*!
 * \file frct_get_L7transaction.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void my_list_node_free(Frlist_node* node)
{
    if(node->data)
        frfree(node->data);
}

static void __case1(void)
{
    Conntrack *p_st_ct = NULL;
    L7_transaction *p_st_l7_transaction=NULL;

    p_st_l7_transaction = frct_get_L7transaction(p_st_ct);

    CU_ASSERT_PTR_NULL(p_st_l7_transaction);

    return;
}

static void __case2(void)
{
    Conntrack *p_st_ct = NULL;
    L7_transaction *p_st_l7_transaction=NULL;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct,0x00,sizeof(Conntrack));

    p_st_l7_transaction = frct_get_L7transaction(p_st_ct);

    CU_ASSERT_PTR_NULL(p_st_l7_transaction);
    frfree(p_st_ct);

    return;
}

static void __case3(void)
{
    Conntrack *p_st_ct = NULL;
    L7_transaction *p_st_l7_transaction=NULL;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct,0x00,sizeof(Conntrack));

    p_st_l7_transaction = frct_get_L7transaction(p_st_ct);

    CU_ASSERT_PTR_NULL(p_st_l7_transaction);
    frfree(p_st_ct);

    return;
}

static void __case4(void)
{
    Conntrack *p_st_ct = NULL;
    L7_analyzer *p_st_l7_analyzer=NULL;
    L7_transaction *p_st_l7_transaction=NULL;
    Frlist_header *p_lst_hdr_l7_proto = NULL;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct,0x00,sizeof(Conntrack));

    p_st_l7_analyzer = (L7_analyzer *)frmalloc(sizeof(L7_analyzer));
    p_st_l7_transaction = (L7_transaction *)frmalloc(sizeof(L7_transaction));


    p_st_ct->st_l7_analyzer.p_st_transaction = p_st_l7_transaction;

    p_st_l7_transaction = frct_get_L7transaction(p_st_ct);

    CU_ASSERT_PTR_NOT_NULL(p_st_l7_transaction);

    frfree(p_st_l7_transaction);
    frfree(p_st_l7_analyzer);
    frlist_remove_all(p_lst_hdr_l7_proto,my_list_node_free);
    frfree(p_st_ct);

    return;
}



int add_suite_frct_get_L7transaction(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frct_comm frct_get_L7transaction()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;
}
